package com.layer8.RPS;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainClass extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btnPickPet = (Button) findViewById(R.id.btnPickPet);
        btnPickPet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getApplicationContext(), PetPicker.class);
                startActivity(intent);
            }
        });
        Button btnBattle = (Button) findViewById(R.id.btnBattle);
        btnBattle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getApplicationContext(), Battle.class);
                startActivity(intent);
            }
        });
        Pet pet = getSavedPet();
        Drawable d = getResources().getDrawable(pet.getImage());
        TextView txtMainPet = (TextView) findViewById(R.id.txtMainPet);
        txtMainPet.setText(pet.getName());
        txtMainPet.setCompoundDrawablesWithIntrinsicBounds(null, null, null, d);
    }

    private Pet getSavedPet() {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        int petID = prefs.getInt("petID", 0);
        PetLoader petLoader = new PetLoader(this);
        petLoader.loadPetList();
        return(petLoader.getPet(petID));
    }
}